//
//  UIButton+EXtensions.swift
//  weibo
//
//  Created by 陈伟 on 15/10/15.
//  Copyright © 2015年 陈伟. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init (imageName: String, backImageName: String?) {
        self.init()
       setImage(UIImage(named: imageName), forState:UIControlState.Normal)
//        setImage(imageName, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName+"_highlighted"), forState: UIControlState.Highlighted)
        
        if backImageName != nil {
        setBackgroundImage(UIImage(named: backImageName!), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: UIControlState.Highlighted)
        }
        sizeToFit()
    }
    
    convenience init(title: String, color: UIColor, imageName: String, fontSize: CGFloat = 12) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }
    
    convenience init(title: String, color: UIColor, backImageName: String, fontSize: CGFloat = 12) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
//        backgroundColor = backColor
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }
    
    
}